package com.leetcode.algorithm.y22.m06;

import java.util.ArrayList;
import java.util.List;

/**
 * 119. 杨辉三角 II
 * 
 * https://leetcode.cn/problems/pascals-triangle-ii/
 * 
 * @author jie.deng
 *
 */
class Question0119Solution01 {

	public List<Integer> getRow(int rowIndex) {
		// numRows=1
		List<Integer> rowList = new ArrayList<>(1);
		rowList.add(1);

		for (int i = 1; i <= rowIndex; i++) {
			List<Integer> prevRowList = rowList;
			rowList = new ArrayList<>(i + 1);
			rowList.add(1);
			for (int j = 1; j < i; j++) {
				rowList.add(prevRowList.get(j - 1).intValue() + prevRowList.get(j).intValue());
			}
			rowList.add(1);
		}
		return rowList;
	}

}